//
//  QWJSONGroupType.m
//  WJJSON
//
//  Created by Yunhai.Wu on 15/9/9.
//  Copyright (c) 2015年 WJ. All rights reserved.
//

#import "QWJSONGroupType.h"
#import "IQWJSONObject.h"

@interface QWJSONGroupType ()
@property (nonatomic, readwrite) Class collectionClass;
@property (nonatomic, readwrite) Class elementClass;
@end
@implementation QWJSONGroupType

-(Class) collectionClass {
    return _collectionClass;
}

-(Class) elementClass {
    return _elementClass;
}

+(QWJSONGroupType *)createCollectionClass:(Class)collectionClass elementClass:(Class)elementClass {
    if (![collectionClass isSubclassOfClass:[NSArray class]] && ![collectionClass isSubclassOfClass:[NSSet class]]) {
        NSString *reason = @"collectionClass必须是NSArray，NSSet类型";
        @throw [[NSException alloc] initWithName:@"QWJSONGroupTypeException" reason:reason userInfo:@{NSLocalizedDescriptionKey:reason}];
        return nil;
    }
    if (![elementClass conformsToProtocol:@protocol(IQWJSONObject)]) {
        NSString *reason = @"elementClass必须是IQWJSONObject类型";
        @throw [[NSException alloc] initWithName:@"QWJSONGroupTypeException" reason:reason userInfo:@{NSLocalizedDescriptionKey:reason}];
        return nil;
    }
    QWJSONGroupType *type = [[QWJSONGroupType alloc] init];
    [type setCollectionClass:collectionClass];
    [type setElementClass:elementClass];
    return type;
}

@end
